/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package br.siseventos.dao;

import br.siseventos.dao.util.HibernateUtil;
import br.siseventos.model.*;
import java.util.ArrayList;
import java.util.List;
import org.hibernate.Criteria;
import org.hibernate.Hibernate;
import org.hibernate.Session;
import org.hibernate.criterion.Restrictions;

/**
 *
 * @author marcosnatanpacheco
 */
public class InscricaoDao extends BaseDao<TbInscricao> {

    public List<TbUsuario> consultar(TbEvento evento) throws Exception {
        Session sessao = HibernateUtil.getSession();
        List<TbUsuario> usuarios = new ArrayList<TbUsuario>();
        TbUsuario p = null;
        try {
            Criteria c = sessao.createCriteria(TbInscricao.class);
            c.add(Restrictions.eq("tbEvento", evento));
            for (TbInscricao i : (List<TbInscricao>) c.list()) {
                p = i.getTbUsuario();
                // Carregando as propriedades Lazy Loading
                Hibernate.initialize(p);
                usuarios.add(p);
            }
        } catch (Exception e) {
            throw e;
        } finally {
            if (sessao != null) {
                sessao.close();
            }
        }
        return usuarios;
    }
}
